"""
集合
    1.定义：它是一个不重复元素容器序列，表示方式{ele1,ele2....}
    2.特性：无序，可变，因为无序，所有不能索引，切片，只能存放不可变的数据，如果存放会报错
    3.内置方法：
        1.add(obj) 添加元素
        2.remove(obj) 删除元素
        3.pop() 从头开始删除元素
        4.issubset 判断另一个集合是否包含这个集合，返回布尔值
    4.集合的运算
        set1 = {1,2,3,4,5,6,7,8,9,10}
        set2 = {1,2,11}
        # 交集
        print(set1 & set2)
        # 并集
        print(set1 | set2)
        # 差集
        print(set1 -set2)
        print(set2-set1)
        # 补集
        print(set1 -set2)
        # 对称差集
        print(set1^set2)        
"""""
# set1 = {1,2,3,4,5,6,7,8,9,10}
# set2 = {1,2,11}
#
#         # 差集
# print(set1 -set2)
# print(set2-set1)
#         # 补集
# print(set1 -set2)
#         # 对称差集
# print(set1^set2)

'''有三个集合，分别表示三门学科的选课学生姓名(一个学生可以同时选多门课)，请解答如下题目
s_history = {'小明', "张三", '李四', "王五", 'Lily', "Bob"}
s_politic = {'小明', "小花", '小红', "二狗"}
s_english = {'小明', 'Lily', "Bob", "Davil", "李四"}
1.求选课学生总共有多少人"
2.求只选了历史的人的数量和对应的名字
3.求只选了一门学科的学生的数量和对应的名字
4.求只选了两门学科的学生的数量和对应的名字
5.求选了三门学生的学生的数量和对应的名字
'''
s_history = {'小明', "张三", '李四', "王五", 'Lily', "Bob"}
s_politic = {'小明', "小花", '小红', "二狗"}
s_english = {'小明', 'Lily', "Bob", "Davil", "李四"}
total_students = s_history | s_politic | s_english
print("选课学生总共有:", len(total_students))

only_history = s_history - (s_politic | s_english)
print("只选了历史的学生数量:", len(only_history), "名字:", ', '.join(only_history))

only_politic = s_politic -(s_history | s_english)
only_english = s_english -(s_history | s_politic)
only_one = only_history | only_politic | only_english
print(f'只选择一门学科的人数是{len(only_one)}，名字：{only_one}')

take_one_students = {s for s in (s_history, s_politic, s_english) if len(s) == 1}
print("只选了一门学科的学生数量:", sum(len(s) for s in take_one_students), "名字:",
      ', '.join({student for subject in take_one_students for student in subject}))
from itertools import combinations
take_two_students = {s1 & s2 for s1, s2 in combinations((s_history, s_politic, s_english), 2) if len(s1 & s2) == 0}
print("只选了两门学科的学生数量为:", sum(len(s) for s in take_two_students), "名字:",
      ', '.join({student for subject in take_two_students for student in subject}))

take_three_students = s_history & s_politic & s_english
print("选了三门学科的学生数量为:", len(take_three_students), "名字:", ', '.join(take_three_students))



# # todo 3.求只选了一门学科的学生的数量和对应的名字
# only_politic = s_politic - (s_history | s_english)
# only_english = s_english - (s_history | s_politic)
# only_one = only_history | only_politic | only_english
# print(f'只选择一门学科的人数是{len(only_one)}，ta们是{only_one}')
#
# # todo 4.求只选了两门学科的学生的数量和对应的名字
# s1 = s_politic & s_history - s_english
# s2 = s_politic & s_english - s_history
# s3 = s_english & s_history - s_politic
# only_two = s1 | s2 | s3
# print(f'只选择一门学科的人数是{len(only_two)}，ta们是{only_two}')

